<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
get_check=function(){
	var ids = '';
	$(".list_table").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;	
};
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"90%", height:"80%", iframe:true});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#request_download").click(function(){
		var current_tag = $(this);
		$(this).attr("disabled", true);
		var url_arr = current_tag.prev().val();
		$.ajax({
			url: "<?=url('Finance::Business/PurchaseDrawbackDownload')?>&url_json=" + url_arr,
			type: "get",
			dataType: "json",
			success:
				function(ret)
				{
					if (ret['ack'] == 'success')
					{
						current_tag.parent().append("<a href='" + ret['url'] + "'>下载文件</a>");
					}
					else
					{
						current_tag.parent().append("请求失败");
					}
				}
		});
	});
	$(".audit").click(function(){
		if (!confirm("确定审核？"))
		{
			return false;
		}
	});
	$("#audit_btn").click(function(){
		var ids = get_check();
		if (!confirm("确定审核？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Finance::Business/PurchaseDrawbackAudit')?>&ids=" + ids;
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<? include (Q::ini('custom_system/elements_dir'). 'searchform_element.php');?>
<table class="form_table">
	<tr>
		<th>退货日期</th>
		<td>
			<input type="text" name="begin_storage_audit_time" class="datepicker" value="<?=isset($_GET['begin_storage_audit_time'])?$_GET['begin_storage_audit_time']:'' ?>" /> to 
			<input type="text" name="end_storage_audit_time" class="datepicker" value="<?=isset($_GET['end_storage_audit_time'])?$_GET['end_storage_audit_time']:'' ?>" />
		</td>
		<td colspan="2"></td>
	</tr>
	<tr>
		<th>财务审核日期</th>
		<td>
			<input type="text" name="begin_finance_audit_time" class="datepicker" value="<?=isset($_GET['begin_finance_audit_time'])?$_GET['begin_finance_audit_time']:'' ?>" /> to 
			<input type="text" name="end_finance_audit_time" class="datepicker" value="<?=isset($_GET['end_finance_audit_time'])?$_GET['end_finance_audit_time']:'' ?>" />
		</td>
		<td colspan="2"></td>
	</tr>
	<tr>
		<th>退货单号</th>
		<td>
			<input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number'])?$_GET['purchase_order_number']:''?>" />
		</td>
		<td colspan="2"></td>
	</tr>
	<tr>
	<tr>
		<th>结款类型</th>
		<td>
			<select name="purchase_order_payment_type">
				<option value="">请选择..</option>
				<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
				<option value="<?=$pt['value']?>" <?if (isset($_GET['purchase_order_payment_type']) && $_GET['purchase_order_payment_type'] == $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
				<? endforeach;?>
			</select>
		</td>
	</tr>
	<th>采购人员</th>
		<td>
			<select name="purchase_user_id">
				<option value="">请选择..</option>
				<?foreach ($user as $u):?>
				<option value="<?=$u['id']?>" <?if (isset($_GET['purchase_user_id'])&&$_GET['purchase_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
				<?endforeach;?>
			</select>
		</td>
	</tr>
	<tr>
		<th>所在仓库</th>
		<td>
			<select name="warehouse_id">
				<option value="">请选择..</option>
				<?foreach ($warehouse as $w):?>
				<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id'])&&$_GET['warehouse_id']==$w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
				<?endforeach;?>
			</select>
		</td>
	</tr>
	<tr>
		<th>财务审核</th>
		<td>
			<?foreach (Q::ini('custom_flag/purchase_order_finance_audit') as $fa):?>
			<label><input type="checkbox" name="finance_audit[<?=$fa['value']?>]" value="<?=$fa['value']?>" <?if (isset($_GET['finance_audit']) && array_key_exists($fa['value'], $_GET['finance_audit'])) echo "checked='checked'";?> /> <?=$fa['name']?></label>
			<?endforeach;?>
		</td>
		<td colspan="2"></td>
	</tr>
	<tr>
		<th></th>
		<td><input type="submit" value="查询" class="button" /></td>
		<th></th>
		<td>
			<input type="hidden" value='<?=$url_json?>' />
			<input type="button" class="button" value="请求下载" id="request_download" />
		</td>
	</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table">
<tr>
	<th width="30"></th>
	<th width="100">退货单号</th>
	<th width="100">所在仓库</th>
	<th width="150">退货日期</th>
	<th width="150">财务审核日期</th>
	<th width="60">经手人</th>
	<th width="60">金额</th>
	<th width="60">状态</th>
	<th width="100">结款类型</th>
	<th>备注</th>
	<th width="120">操作</th>
</tr>
<?foreach ($purchase_order as $po):?>
<tr>
	<td><input type="checkbox" value="<?=$po['id']?>" /></td>
	<td><a class="detail" href="<?=url('Finance::Business/PurchaseDetail', array('id' => $po['id']))?>"><?=$po['number']?></a></td>
	<td><?=$po['warehouse_name']?></td>
	<td><?=$po['storage_audit_time']?></td>
	<td><?=$po['finance_audit_time']?></td>
	<td><?=$po['purchase_user_name']?></td>
	<td><?=sprintf('%.2f', $po['actual_amount'])?></td>
	<td>
		<?if ($po['status'] == Q::ini('custom_flag/purchase_order_status/storaged/value')):?>已退<?else:?>待退<?endif;?>
	</td>
	<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type', 'value', $po['payment_type'], 'name')?></td>
	<td><?=$po['notes']?></td>
	<td>
		<?if ($po['finance_audit'] == Q::ini('custom_flag/purchase_order_finance_audit/unaudit/value') && $po['status'] == Q::ini('custom_flag/purchase_order_status/storaged/value')):?>
		<a href="<?=url('Finance::Business/PurchaseDrawbackAudit', array('ids'=>$po['id']))?>" class="audit">审核</a>
		<?else:?>
		<font color="#aaaaaa">审核</font>
		<?endif;?>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<label><input type="checkbox" id="check_all" /> 全选</label>
<input type="button" class="button" value="合并审核" id="audit_btn" />
搜索条件的总金额：RMB<big><b><?=number_format($amount, 2)?></b></big>
<?php $this->_endblock(); ?>